package com.alai04.android.scoreboard;

import java.util.Arrays;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;

public class Scoreboard extends Activity {
	public static String contactNames[];
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        getNamesFromContacts();
    }
    
    public void startClick(View view) {
    	Intent i = new Intent(this, ScoreViewer.class);
    	i.putExtra(ScoreViewer.KEY_CONTINUE, (view == findViewById(R.id.cont_button)));
        startActivity(i);
    }
    
    public void setupClick(View view) {
    	Intent i = new Intent(this, Prefs.class);
        startActivity(i);
    }
    
    public void exitClick(View view) {
    	finish();
    }
    
    private void getNamesFromContacts() {
		// Get a cursor over every aggregated contact.
		Cursor cursor = getContentResolver().query(
				ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

		// Let the activity manage the cursor lifecycle.
		startManagingCursor(cursor);

		// Use the convenience properties to get the index of the columns
		int nameIdx = cursor
				.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);

		contactNames = new String[cursor.getCount()];
		if (cursor.moveToFirst())
			do {
				// Extract the name.
				contactNames[cursor.getPosition()] = cursor.getString(nameIdx);
			} while (cursor.moveToNext());

		stopManagingCursor(cursor);
		Arrays.sort(contactNames);
    }
    
}